package com.childenglish.controller;

import com.childenglish.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system")
public class SystemController {

    @RequiresPermissions("system:user:list")
    @GetMapping("/user/list")
    public R getUserList() {
        List<Map<String, Object>> users = new ArrayList<>();

        users.add(createUser(1L, "admin", "管理员", "00", "0"));
        users.add(createUser(2L, "parent_zhang", "张爸爸", "01", "0"));
        users.add(createUser(3L, "child_xiaoming", "小明", "02", "0"));
        users.add(createUser(4L, "teacher_li", "李老师", "03", "0"));

        return R.ok("获取用户列表成功").data(users);
    }

    @RequiresPermissions("system:role:list")
    @GetMapping("/role/list")
    public R getRoleList() {
        List<Map<String, Object>> roles = new ArrayList<>();

        roles.add(createRole(1L, "超级管理员", "admin", "0"));
        roles.add(createRole(2L, "家长", "parent", "0"));
        roles.add(createRole(3L, "幼儿", "child", "0"));
        roles.add(createRole(4L, "教师", "teacher", "0"));

        return R.ok("获取角色列表成功").data(roles);
    }

    private Map<String, Object> createUser(Long id, String name, String nickName, String type, String status) {
        Map<String, Object> user = new HashMap<>();
        user.put("userId", id);
        user.put("userName", name);
        user.put("nickName", nickName);
        user.put("userType", type);
        user.put("status", status);
        return user;
    }

    private Map<String, Object> createRole(Long id, String name, String key, String status) {
        Map<String, Object> role = new HashMap<>();
        role.put("roleId", id);
        role.put("roleName", name);
        role.put("roleKey", key);
        role.put("status", status);
        return role;
    }
}